const moment = require("../../miniprogram_npm/moment/index.js")
const Protocol = require("../../Controls/Protocol")
const util = require ("../../utils/util")
const Product = require("../../model/Product")

var data = 
{
  
    currentPage: 1,
    maxPage: 1,
    info:
    {
      indicatorDots: true,
      autoPlay: false,
      interval: false,
      duration: 300,
      empty_txt:"没有参与任何秘袋",
      ingProduct:
      [
        //{name:"产品ing1", images:["../../image/yellowchild.jpg", "../../image/1.jpg"]},
        //{ name: "产品ing2", images:["../../image/yellowchild.jpg", "../../image/1.jpg"] },
        //{ name: "产品ing3", images: ["../../image/yellowchild.jpg", "../../image/1.jpg"] },
        //{ name: "产品ing4", images: ["../../image/yellowchild.jpg"] },
        
      ],

      otherProduct:
      [
        /*
        { name: "名字1", images: ["../../image/kefu.png", "../../image/1.jpg"] },
        { name: "名字2", images: ["../../image/kefu.png", "../../image/1.jpg"] },
        { name: "名字3", images: ["../../image/kefu.png", "../../image/1.jpg"] },
        */
      ]
    }
}

function onSuccess(that, res)
{
  data.currentPage = res.data.data.page;
  data.maxPage = res.data.data.maxPage;

  var ing = new Array();
  var other = new Array();

  for (var i = 0; i < res.data.data.items.length; i++) {
    var item = res.data.data.items[i];
    var viewItem = Product.newProduct(item);
    var now = moment();
    if (now > viewItem.expriceTime) {
      other.push(viewItem);
    }
    else {
      ing.push(viewItem);
    }
  }

  var newInfo =
  {
    indicatorDots: true,
    autoPlay: true,
    interval: false,
    duration: 300,
    empty_txt: "没有参与任何秘袋",
    ingProduct: ing,
    otherProduct: other
  };

  that.setData({ info: newInfo });
}

function onFail(that, res)
{

}


function onComplete(that, res)
{

}

var onLoad = function(args)
{
  var opt =
  {
    success: (res) => { onSuccess(this, res) },
    fail: (res) => { onFail(this, res) },
    complete: (res) => { this, res }
  };

  Protocol.myAttanded(1, opt);
}

function onClickIngitemIvk(event) {
  var id = event.currentTarget.dataset.item.id;
  wx.navigateTo({ url: `../../pages/product/product?id=${id}` })
}

var options = 
{
  data,
  onLoad,
  onClickIngitemIvk
}

Page(options)